home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / rbbs_pc / mnt_201.zip / FIXIT.C < prev    next >
Text File  |  1992-01-05  |  6KB  |  163 lines

  1. /****************************************************************************/
  2. /* FIXIT module for RBBSMNT v2.01, a maintenance utility for RBBS-PC        */
  3. /*╒═════════════════════════════ NOTICE ═══════════════════════════════════╕*/
  4. /*│  A limited license is granted to all users of this program to make     │*/
  5. /*│  copies if this program and distribute those copies to other users     │*/
  6. /*│  on the following three conditions:                                    │*/
  7. /*│                                                                        │*/
  8. /*│    1.   This notice is NOT altered, bypassed or removed,               │*/
  9. /*│    2.   The program is not to be distributed to others in modified     │*/
  10. /*│         form. You may make changes for your own non-commercial use     │*/
  11. /*│    3.   No fee is to be charged (or any other consideration received)  │*/
  12. /*│         for copying or distributing these programs without an express  │*/
  13. /*│         written agreement with J. Terpstra, Bamestra RBBS, PO Box 66,  │*/
  14. /*│         Beemster, The Netherlands.                                     │*/
  15. /*│                                                                        │*/
  16. /*│Copyright (C) 1991, 1992 - Jan Terpstra, Bamestra RBBS, The Netherlands.│*/
  17. /*╘════════════════════════════════════════════════════════════════════════╛*/
  18. /****************************************************************************/
  19.  
  20. #include "rbbsmnt.h"                    /* definitions for this program     */
  21. #include "externs.h"                    /* external data references         */
  22. int rcount;                             /* # msgs read                      */
  23. int wcount;                             /* # msgs written                   */
  24. int last_one;
  25.  
  26.   /**************************************************************************/
  27.   /* repair messages file                                                   */
  28.   /**************************************************************************/
  29.  
  30. char *virgin = "                               -1 0 0 0 0 0 0 0    0 0 0I   \
  31.                                                                     ";
  32. void repair(void)
  33. {
  34.    int cur_rec = 0;
  35.    int num_rec = 0;
  36.    int nhm ,j,msg,x1,x2;
  37.    long msgpos;
  38.    sprintf(logbuf,"Repairing HEADER and NODE reords of %s",msgfile);
  39.    writelog(logbuf, 1, 3);
  40.  
  41.    if ((msg = open(msgfile, O_RDWR|O_BINARY)) == ERROR)
  42.    {
  43.       sprintf(logbuf, "Error opening %s.", msgfile);
  44.       writelog(logbuf, 1, 0);
  45.       return ;
  46.    }
  47.    last_rec = (int)(lseek(msg, 0L, SEEK_END)/128L);/* get real filesize     */
  48.    lseek(msg, 0L, SEEK_SET);            /* seek to header                   */
  49.  
  50.    /*************************************************************************/
  51.    /* find first message                                                    */
  52.    /*************************************************************************/
  53.  
  54.  
  55.    while (cur_rec < last_rec)           /* search for a msg header          */
  56.    {
  57.       read(msg, (char *)&msg_hdr, (size_t)sizeof(RBBSMSG));
  58.       cur_rec++;
  59.  
  60.       if (msg_hdr.enter_date[2] == '-' && msg_hdr.enter_date[5] == '-' &&
  61.       msg_hdr.enter_time[2] == ':')     /* got a real message header?       */
  62.       {
  63.          first_rec = cur_rec;
  64.          cur_rec += num_rec;
  65.          next_rec = cur_rec;
  66.          sscanf(msg_hdr.num_recs, "%4u", &num_rec);
  67.          sscanf(msg_hdr.msg_number, "%4u", &high_msg);
  68.          nhm = high_msg;
  69.          break;
  70.  
  71.       }
  72.    }
  73.  
  74.    /*******************************************************************/
  75.    /* find other messages                                             */
  76.    /*******************************************************************/
  77.  
  78.  
  79.    do
  80.    {
  81.       msgpos = (long)(cur_rec-1)*128L;
  82.       lseek(msg, msgpos, SEEK_SET);     /* move to start of next message         */
  83.       read(msg, (char *)&msg_hdr, (size_t)sizeof(RBBSMSG));
  84.       cur_rec++;
  85.  
  86.       if (msg_hdr.enter_date[2] == '-' && msg_hdr.enter_date[5] == '-' &&
  87.       msg_hdr.enter_time[2] == ':')     /* got a real message header?       */
  88.       {
  89.          sscanf(msg_hdr.num_recs, "%4u", &num_rec);
  90.          sscanf(msg_hdr.msg_number, "%4u", &nhm);
  91.          if (nhm > high_msg)
  92.          {
  93.             high_msg = nhm;
  94.          }
  95.          cur_rec += num_rec-1;
  96.          next_rec = cur_rec;
  97.       }
  98.  
  99.       else
  100.       {
  101.  
  102.          while (cur_rec < last_rec)     /* search for a msg header          */
  103.          {
  104.             read(msg, (char *)&msg_hdr, (size_t)sizeof(RBBSMSG));
  105.  
  106.             if (msg_hdr.enter_date[2] == '-' && msg_hdr.enter_date[5] == '-'
  107.             && msg_hdr.enter_time[2] == ':')/* got a real message header?   */
  108.             {
  109.                break;
  110.             }
  111.             cur_rec++;
  112.          }
  113.       }
  114.    }
  115.  
  116.    while (cur_rec < last_rec);
  117.  
  118.    /*************************************************************************/
  119.    /* restore the message header                                            */
  120.    /*************************************************************************/
  121.    printf("  How many copies of RBBS share this msg file (1...36) : ");
  122.    scanf("%u",&x1);
  123.    first_rec = x1+2;
  124.    printf("  Security level to join this conference (1...32000)   : ");
  125.    scanf("%u" , &x2);
  126.  
  127.    if (next_rec < first_rec)
  128.    {
  129.      next_rec = first_rec;
  130.    }
  131.  
  132.    if (last_rec < first_rec-1)
  133.    {
  134.      last_rec = first_rec -1;
  135.    }
  136.  
  137.    memset(&hdr, ' ', sizeof(RBBSHDR));  /* read header                      */
  138.    lseek(msg, 0L, SEEK_SET);            /* seek to header                   */
  139.  
  140.    for (j = 1; j < first_rec; j++)
  141.    {
  142.       write(msg, virgin, (int)sizeof(RBBSHDR));
  143.    }
  144.    itos(high_msg, hdr.last_msg, 8);
  145.    itos(1, hdr.user_count, 5);
  146.    memset(&hdr.spare, ' ' ,6);
  147.    itos(first_rec, hdr.first_msg_rec, 7);
  148.    itos(next_rec, hdr.next_free_rec, 7);
  149.    itos(last_rec, hdr.last_msg_rec, 7);
  150.    itos(999, hdr.max_message, 7);
  151.    itos(x1, hdr.num_nodes, 2);
  152.    hdr.joinsec = x2;
  153.    lseek(msg, 0L, SEEK_SET);            /* seek to header                   */
  154.    write(msg, (char *)&hdr, (int)sizeof(RBBSHDR));
  155.    max_msgs = 999;
  156.    do_clean = TRUE;
  157.    do_renum = TRUE;
  158.    pip = FALSE;
  159.    quiet = FALSE;
  160.  
  161. }
  162.  
  163.